package com.hua.Dao;

import java.sql.*;

public class Mysql {
    //对SQL引擎的封装
    //封装一个连接的方法
    public static Connection GetConn() throws SQLException {
        Connection connection = DriverManager.getConnection("jdbc:mysql://10.157.0.7:3306/webdisk?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&characterEncoding=UTF-8", "root", "pie2983");
        return connection;
    }

    //封装一个关闭的方法(先关闭预编译对象，在关闭resultSet，最后关闭连接)
    public static void CloseConn(PreparedStatement preparedStatement, ResultSet resultSet, Connection connection) throws SQLException {
        if (preparedStatement != null) {
            preparedStatement.close();  //关闭预编译对象
        }
        if (resultSet != null) {  //关闭返回对象
            preparedStatement.close();
        }
        if (connection != null) {  //关闭连接
            connection.close();
        }
    }
}

